//
//  pop_func.m
//  penzer
//
//  Created by caiyc on 2018/10/2.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "pop_func.h"
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
#define ALERT_HTIGHT 400
@interface pop_func()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) UIView *alertview;
@property (nonatomic,strong)UILabel *titleLab;
@property (nonatomic,strong)UILabel *messageLab;
@property (nonatomic,strong)UIButton *cancelBtn;
@property (nonatomic,strong)UIButton *otherBtn;
@property(nonatomic,strong)UIImageView *backImg;
@property(nonatomic,strong)UIImageView *left_Img;
@property(nonatomic,strong)UIImageView *right_Img;
@property(nonatomic,strong)UIButton *left_Btn;
@property(nonatomic,strong)UIButton *right_Btn;
@property(nonatomic,strong)UIView *examView;
@property(nonatomic,strong)UIButton *cofirm_Btn;
@property(nonatomic,strong)UIButton *close_Btn;
@end
@implementation pop_func
-(instancetype)init{
    self = [super init];
    if(self){
        
        
        
        self.frame = [UIScreen mainScreen].bounds;

        self.alertview.frame = CGRectMake(0, screen_height-180, SCREEN_WIDTH, 180);
        [self.alertview addSubview:self.backImg];
        //  self.alertview.center = self.center;
        [self addSubview:self.alertview];
        NSArray *images = @[@"Group 15",@"Group 16",@"Group 17",@"喜欢"];
        NSArray *titles = @[@"分享直播",@"举报",@"关闭弹幕",@"收藏直播间"];
        CGFloat imageWidth = screen_width/images.count;
        NSInteger imagewidth = 40;
        for(int i =0;i<images.count;i++){
            UIView *item_View = [[UIView alloc]initWithFrame:CGRectMake(imageWidth*i, 20, imageWidth, 100)];
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageWidth/2-imagewidth/2, 15, 40, 40)];
            imageView.image = [UIImage imageNamed:images[i]];
            [item_View addSubview:imageView];
            
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 70, imageWidth, 30)];
            title.textColor = [UIColor whiteColor];
            title.font = [UIFont systemFontOfSize:15];
            title.text = titles[i];
            title.textAlignment = NSTextAlignmentCenter;
            title.tag = 1024+i;
            [item_View addSubview:title];
            [self.alertview addSubview:item_View];
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(0, 0, imageWidth, 100);
            btn.tag = i;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [item_View addSubview:btn];
            
            
        }
        UIButton *close_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
        close_Btn.frame = CGRectMake(screen_width/2-20, 130, 40, 40);
        [close_Btn setImage:[UIImage imageNamed:@"关  闭"] forState:UIControlStateNormal];
        close_Btn.tag = 10;
        [close_Btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.alertview addSubview:close_Btn];
        
//        self.examView = [[UIView alloc]initWithFrame:CGRectMake(30, 130, screen_width-60, 280)];
//        self.examView.backgroundColor = [UIColor whiteColor];
//        self.examView.layer.cornerRadius = 5;
//        self.examView.layer.masksToBounds = 1;
//
//        [self.alertview addSubview:self.examView];
//
//        self.cofirm_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        self.cofirm_Btn.frame = CGRectMake(screen_width/2-100, 420, 200, 50);
//        self.cofirm_Btn.backgroundColor = [UIColor whiteColor];
//        self.cofirm_Btn.layer.cornerRadius = 25;
//        self.cofirm_Btn.layer.masksToBounds = 1;
//        [self.cofirm_Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [self.cofirm_Btn setTitle:@"提交答案" forState:UIControlStateNormal];
//        [self.alertview addSubview:self.cofirm_Btn];
//        [self.cofirm_Btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//
//        self.close_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        self.close_Btn.frame = CGRectMake(screen_width-60, 10, 50, 30);
//        [self.close_Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [self.close_Btn setTitle:@"收起" forState:UIControlStateNormal];
//        self.close_Btn.titleLabel.font = [UIFont systemFontOfSize:13];
//        [self.alertview addSubview:self.close_Btn];
//        [self.close_Btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    return self;
    
}
-(void)btnClick:(UIButton *)btn{
    //    if ([self.delegate respondsToSelector:@selector(AlertView:clickedButtonAtIndex:)]) {
    //        [self.delegate dxAlertView:self clickedButtonAtIndex:btn.tag];
    //    }
    if([self.delegate respondsToSelector:@selector(AlertView:clickedButtonAtIndex:)]){
        [self.delegate AlertView:self clickedButtonAtIndex:btn.tag];
    }
    [self dismissAlertView];
}
-(void)dismissAlertView{
    [UIView animateWithDuration:0.3 animations:^{
        [self removeFromSuperview];
    }];
}
-(UIView *)alertview
{
    if (_alertview == nil) {
        _alertview = [[UIView alloc] init];
        _alertview.backgroundColor = RGBA(0, 0, 0, .7);
       // _alertview.layer.cornerRadius=5.0;
        _alertview.layer.masksToBounds=YES;
        _alertview.userInteractionEnabled=YES;
    }
    return _alertview;
}
-(void)show:(BOOL)danmuStatus Andcollect:(BOOL)collct
{
    self.backgroundColor = [UIColor clearColor];
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0);
    UILabel *title = (UILabel *)[self viewWithTag:1026];
    if(danmuStatus==1){
        
        title.text = @"关闭弹幕";
    }else{
        title.text = @"开启弹幕";
    }
     UILabel *title1 =(UILabel *)[self viewWithTag:1027];
    if(collct==1){
       
        title1.text= @"收藏直播间";
    }else{
        title1.text= @"取消收藏";
    }
    self.alertview.transform = CGAffineTransformScale(CGAffineTransformIdentity,0,0);
   // self.alertview.alpha = 0;
    [UIView animateWithDuration:0.3 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.4f];
        self.alertview.transform = transform;
        self.alertview.alpha = 1;
    } completion:^(BOOL finished) {
        
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
